package com.demo2do.fms.admin.entity.query;

import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.driver.DriverAuditStatus;

/**
 * 司机的辅助查询
 * 
 * @author Wy
 *
 */
public class DriverQuery implements QueryBuilder{
    
    /** 司机所属供方 */
    private Long supplierId;
     
    /** 司机代码 */
    private String code;

    /** 司机名称 */
    private String name;

    /** 司机身份证号 */
    private String citizenCode;

    private QueryOrder order;

    private QueryFilter filter;

    public DriverQuery() {
        order = new QueryOrder();
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (filter == null || refresh) {

            filter = new QueryFilter().addEquals("status", DriverAuditStatus.QUALIFIED)
                                      .addEquals("supplier.id", supplierId)
                                      .addLike("code", code)
                                      .addLike("name", name)
                                      .addLike("citizenCode", citizenCode);

        }

        return filter;
    }

	/*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
	public QueryOrder getOrder() {
		return order;
	}

	/*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
	public String buildSentenceTemplate() {
		String sentence = "FROM Driver WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
		return sentence;
	}

	/*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
	public Map<String, Object> buildParameters() {
		return getPreparedFilter(false).parameters();
	}
	
	/**
     * 
     * @return
     */
	public QueryFilter getFilter(){
		return getPreparedFilter(false);
	}
	
	/**
	 * @return
	 */
	public Long getSupplierId() {
        return supplierId;
    }

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the citizenCode
	 */
	public String getCitizenCode() {
		return citizenCode;
	}
	
	/**
	 * @param supplierId
	 */
	public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param citizenCode the citizenCode to set
	 */
	public void setCitizenCode(String citizenCode) {
		this.citizenCode = citizenCode;
	}

}
